package com.molin.threadTest.threadDemo3;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable=new MyCallable();
        FutureTask<String> ft=new FutureTask<>(myCallable);
        Thread thread=new Thread(ft);


        MyCallable myCallable2=new MyCallable();
        FutureTask<String> ft2=new FutureTask<String>(myCallable2);
        Thread thread2=new Thread(ft2);
        thread2.start();
        thread.start();

        //获取线程的执行结果，不能在start()方法之前调用。
        String s = ft.get();
        System.out.println(s);
    }
}
